package com.edu.schoolforum.controller;

import com.edu.schoolforum.enums.ResultEnum;
import com.edu.schoolforum.pojo.ImgUrl;
import com.edu.schoolforum.pojo.PhotoUrl;
import com.edu.schoolforum.service.PhotoService;
import com.edu.schoolforum.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tao
 * @date 2021/8/28 11:21
 */
@Controller
@RestController
@RequestMapping("/api")
public class PhotoController {
     @Autowired
     PhotoService photoService;

     @PostMapping("/insertPhoto")
    public CommonResult insertPhoto(@RequestBody ImgUrl imgUrl){
         int i= photoService.insertPhoto(imgUrl);
         if(i==0){
             return CommonResult.fail(ResultEnum.INSERT_PHOTO_FAIL);
         }else{
             return CommonResult.success();
         }
     }

     @PostMapping("/selectAllPhoto")
    public CommonResult selectAllPhoto(){
         List<PhotoUrl> list=photoService.selectImgUrl();
         return CommonResult.success(list);
     }

     @PostMapping("/deletePhoto")
    public CommonResult deletePhoto(@RequestParam("id")Integer id){
         int i= photoService.deletePhoto(id);
         if(i==0){
             return CommonResult.fail(ResultEnum.DELETE_PHOTO_FAIL);
         }else{
             return CommonResult.success();
         }
     }


}
